package 王道.线性表.链式表;

import 王道.数据结构.SqList;

public class Question1 {
    //删除最小值元素（假设唯一）并返回该值，后面元素递补
    int deletemin(SqList list) {
        if (list.length == 0) {
            System.out.println("顺序表为空，无法删除");
            return -1;
        }
        int min_i = 0;
        for (int i = 1; i < list.length; i++) {
            if (list.data[i] < list.data[min_i])
                min_i = i;
        }
        int t = list.data[min_i];
        for (int i = min_i; i < list.length - 1; i++) {
            list.data[i] = list.data[i + 1];
        }
        list.length -= 1;
        return t;
    }

    public static void main(String[] args) {
        SqList sqList = new SqList();
        int[] nums = {2,4,1,5,2,52,5,6};
        sqList.data = nums;
        sqList.length = nums.length;
        int deletemin = new Question1().deletemin(sqList);
        System.out.println(deletemin);
        System.out.println(sqList);
    }
}
